package com.mba.bean;

import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

import com.mba.util.Utility;

import android.os.Message;

/*
 * resource class of Comment
 * 
 * Written by pansen at 2013/04/17
 * 
 */
public class Comment {
	/*
	 * ID of comment
	 */
	private long messageID;
	/*
	 * content of comment
	 */
	private String text;
	/*
	 * creatTime
	 */
	private Date createAt;

	/*
	 * the message of the comment belong to
	 */
	private Message message;
	/*
	 * user that create comment
	 */
	private UserBasic user;
	/*
	 * the comment reply to which comment
	 */
	private long replyCommentID;
	
	
	public Comment(JSONObject jsonObj) throws Exception{
		constructJson(jsonObj);
	}

	public Comment(long commentID, String text, Date createAt, Message message,
			UserBasic user, long replyCommentID) {
		this.messageID = commentID;
		this.text = text;
		this.createAt = createAt;
		this.message = message;
		this.user = user;
		this.replyCommentID = replyCommentID;
	}
	
	private void constructJson(JSONObject json) throws Exception {
		try {
			messageID = Utility.getLong("id",json);
			createAt = Utility.parseDate(json.getString("created_at"), "yyyy-MM-dd HH:mm");
			text = json.getString("text");
			if(!json.isNull("user")){
				user = new UserBasic(json.getJSONObject("user"));
			}
		} catch (JSONException je) {
			throw je;
		}
	}


	public long getMessageID() {
		return messageID;
	}


	public void setMessageID(long messageID) {
		this.messageID = messageID;
	}


	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Date getCreateAt() {
		return createAt;
	}

	public void setCreateAt(Date createAt) {
		this.createAt = createAt;
	}

	public Message getMessage() {
		return message;
	}

	public void setMessage(Message message) {
		this.message = message;
	}

	public UserBasic getUser() {
		return user;
	}

	public void setUser(UserBasic user) {
		this.user = user;
	}

	public long getReplyCommentID() {
		return replyCommentID;
	}

	public void setReplyCommentID(long replyCommentID) {
		this.replyCommentID = replyCommentID;
	}
	

}
